//
//  MemberCenterViewC.m
//  WHSport
//
//  Created by ccjoy-jimneylee on 15/3/26.
//  Copyright (c) 2015年 jimneylee. All rights reserved.
//

#import "MemberCenterViewC.h"
#import "Util.h"
#import "MemHealthyViewC.h"
#import "FriendListViewC.h"
#import "MyCollectionViewC.h"
#import "MemSetViewC.h"
#import "PersonalViewC.h"
#import "MyOrderViewC.h"
#import "MyWarViewC.h"
#import "QRcodeViewC.h"
#import "MyEvaViewC.h"
#import "SendCommtViewC.h"
#import <UIImageView+AFNetworking.h>
#import "UserModel.h"


@interface MemberCenterViewC ()


@end

@implementation MemberCenterViewC{
    
    NSArray *_name;
    NSArray *_image;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title =@"个人中心";
    _headImg.layer.cornerRadius = 30;
    _headImg.clipsToBounds = YES;
    [self getData];
    
    UITapGestureRecognizer *singleTouch = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(personalBtn:)];
    [_personView addGestureRecognizer:singleTouch];
    
}

- (void)getData{
    
    _nickLab.text = [NSString stringWithFormat:@"%@",[UserModel sharedInstance].currentUser.nick];
    _placeLab.text = [NSString stringWithFormat:@"%@",[UserModel sharedInstance].currentUser.address];
    NSString *str = [NSString stringWithFormat:@"%@",[UserModel sharedInstance].currentUser.sex];
    NSString *sex = [Util getsexWithImg:str];
    _sexImg.image = [UIImage imageNamed:sex];
    NSString *img = [NSString stringWithFormat:
                     @"http://218.93.12.178:8080/hhw-api/%@",
                     [UserModel sharedInstance].currentUser.headpic];
    NSURL *url = [NSURL URLWithString:img];
    [_headImg setImageWithURL:url];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self getData];
}

-(void)personalBtn:(id)sender{
    UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main"
                                                   bundle:nil];
    PersonalViewC *pervc = [main instantiateViewControllerWithIdentifier:@"PersonalViewC"];
    
    [self.navigationController pushViewController:pervc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)loginoutBtn:(id)sender{
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                  message:@"确定退出吗？"
                                                 delegate:self
                                        cancelButtonTitle:@"取消"
                                        otherButtonTitles:@"确定",nil];
    
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    NSString* msg = [[NSString alloc] initWithFormat:@"%ld",buttonIndex];
    if ([msg isEqualToString:@"1"]) {
        [UserModel sharedInstance].currentUser = nil;
        [self.navigationController popViewControllerAnimated:YES];
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    
    UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main"
                                                   bundle:nil];
    
    if (indexPath.row == 0) {
        MemHealthyViewC *memvc = [main instantiateViewControllerWithIdentifier:@"MemHealthyViewC"];
        [self.navigationController pushViewController:memvc animated:YES];
    }
    
    if (indexPath.row == 1) {
        MyOrderViewC *myomvc = [main instantiateViewControllerWithIdentifier:@"MyOrderViewC"];
    [self.navigationController pushViewController:myomvc animated:YES];
    }
    
    if (indexPath.row == 3) {
        FriendListViewC *frivc = [main instantiateViewControllerWithIdentifier:@"FriendListViewC"];
        [self.navigationController pushViewController:frivc animated:YES];
    }
    
    if (indexPath.row == 4) {
        MyWarViewC *mywvc = [main instantiateViewControllerWithIdentifier:@"MyWarViewC"];
        [self.navigationController pushViewController:mywvc animated:YES];
    }
    
    if (indexPath.row == 5) {
        MyCollectionViewC *myvc = [main instantiateViewControllerWithIdentifier:@"MyCollectionViewC"];
        [self.navigationController pushViewController:myvc animated:YES];
    }
    if (indexPath.row == 6) {
        MyEvaViewC *myevc = [main instantiateViewControllerWithIdentifier:@"MyEvaViewC"];
        [self.navigationController pushViewController:myevc animated:YES];
    }
    
    if (indexPath.row == 7) {
        QRcodeViewC *qrvc = [[QRcodeViewC alloc]
                                 initWithNibName:@"QRcodeViewC"
                                 bundle:nil];
        [self.navigationController pushViewController:qrvc animated:YES];
    }
    
    if (indexPath.row == 8) {
        MemSetViewC *memvc = [main instantiateViewControllerWithIdentifier:@"MemSetViewC"];
        [self.navigationController pushViewController:memvc animated:YES];
    }
    
    


}



@end
